﻿using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Storage;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using x.Domain;
using x.Domain.User;

namespace x.EntityFrameworkCore
{
    public class MyDbContext:DbContext
    {
        public MyDbContext(DbContextOptions dbContextOptions):base(dbContextOptions)
        {
            
        }
        //1 配置连接字符串
        //protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
        //{
        //    //连接字符串
        //    string connStr = @"Data Source=LAPTOP-EBVO6PKT\MSSQLSERVER02;Initial Catalog=A31902;User ID=sa;pwd=123;Encrypt=False;";
        //    optionsBuilder.UseSqlServer(connStr);
        //}
        //2 读取配置类
        protected override void OnModelCreating(ModelBuilder modelBuilder)
        {
            //读取配置文件
            //modelBuilder.ApplyConfiguration(new UserConfiger());//具体类
            //程序集
            modelBuilder.ApplyConfigurationsFromAssembly(this.GetType().Assembly);
        }
        //3 根据实体类名创建操作对象
        public DbSet<Users> Users { get; set; }
    }
}
